package com.cykj.pos.insideLogin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cykj.common.core.domain.entity.SysUser;
import com.cykj.pos.insideLogin.domain.InsideUser;
import com.cykj.pos.insideLogin.mapper.provider.InsideLoginMapperProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Set;

/**
 * @author wangjiaqi
 * @date 2021/12/29
 */
public interface InsideLoginMapper extends BaseMapper<InsideUser> {

    @SelectProvider(type = InsideLoginMapperProvider.class, method = "findUser")
    List<InsideUser> findUser(String nickName);

    @Select("SELECT perms FROM sys_menu WHERE menu_id in( " +
            "SELECT menu_id FROM sys_role_menu WHERE role_id = ( " +
            "SELECT role_id FROM sys_user_role WHERE user_id = ( " +
            "SELECT user_id FROM sys_user WHERE user_name = #{userName} and nick_name = #{nickName} ))) and perms <> '' ")
    Set<String> getPermissions(@Param("userName") String userName, @Param("nickName") String nickName);

    @Select("SELECT * FROM sys_user WHERE user_name = #{userName} and nick_name = #{nickName} ")
    SysUser getUserInfo(@Param("userName") String userName, @Param("nickName") String nickName);
}
